package top.minuy.structure.graph.cc.dfs;

import top.minuy.res.graph.GraphRes;
import top.minuy.structure.graph.representations.table.Graph;

import java.util.ArrayList;

/**
 * 测试联通分量
 *
 * @author Minuy
 * @time 17:51
 * @date 2021/11/16
 */
public class Test {
    public static void main(String[] args) {
        System.out.println("先序遍历求联通分量：");
        Graph graph = new Graph(GraphRes.G_DFS_1);

        CCV1 ccv1 = new CCV1(graph);
        System.out.println("联通分量V1：" + ccv1.count());

        CCV2 ccv2 = new CCV2(graph);
        System.out.println("联通分量V2：" + ccv2.count());
        System.out.println("联通V2：" + ccv2.isConnected(1,6));
        System.out.println("联通V2：" + ccv2.isConnected(5,2));
        System.out.println("联通V2：" + ccv2.isConnected(7,6));
        ArrayList<Integer>[] comp = ccv2.components();
        for (int i = 0; i < comp.length; i++) {
            System.out.print(i +" : ");
           for (Integer v:comp[i]){
               System.out.print(v+ " ");
           }
           System.out.println();
        }
    }
}
